package com.shihb.behavioralpatterns.observerpattern;

import java.util.ArrayList;
import java.util.List;

/**
 *Description:
 *Version:1.0.0
 *@author shihb
 *@date 2020/7/28 21:41
 */
public class WeatherStation implements Subject {
  private List<Observer> list;
  private String temperature;
  private String humidity;

  public WeatherStation() {
    list=new ArrayList();
  }

  @Override
  public void register(Observer observer) {
    list.add(observer);
  }

  @Override
  public void remove(Observer observer) {
    list.remove(observer);

  }

  @Override
  public void notification() {
    for(Observer o:list){
      o.update(this.temperature,this.humidity);
    }

  }

  public void setData(String temperature,String humidity) {
    this.temperature = temperature;
    this.humidity=humidity;
    notification();
  }


}
